package cn.demo.um.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import cn.demo.common.annotation.Log;
import cn.demo.common.core.controller.BaseController;
import cn.demo.common.core.domain.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.demo.common.enums.BusinessType;
import cn.demo.um.domain.UmContentFocus;
import cn.demo.um.service.IUmContentFocusService;
import cn.demo.common.utils.poi.ExcelUtil;
import cn.demo.common.core.page.PageR;
import cn.demo.common.core.page.PageQuery;
import com.mybatisflex.core.paginate.Page;


/**
 * 用户文章点赞Controller
 *
 * @author xtjun
 * @date 2024-06-06
 */
@Tag(name = "用户文章点赞")
@RestController
@RequestMapping("/um/umContentFocus")
public class UmContentFocusController extends BaseController {
    @Resource
    private IUmContentFocusService umContentFocusService;

    @Operation(summary = "查询用户文章点赞列表")
    @PreAuthorize("@ss.hasPermi('um:umContentFocus:list')")
    @GetMapping("/list")
    public PageR<UmContentFocus> list(UmContentFocus umContentFocus, PageQuery pageQuery) {
        Page<UmContentFocus> page = umContentFocusService.selectUmContentFocusPage(umContentFocus, pageQuery);
        return PageR.ok(page);
    }

    @Operation(summary = "导出用户文章点赞列表")
    @PreAuthorize("@ss.hasPermi('um:umContentFocus:export')")
    @Log(title = "用户文章点赞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UmContentFocus umContentFocus) {
        List<UmContentFocus> list = umContentFocusService.selectUmContentFocusList(umContentFocus);
        ExcelUtil<UmContentFocus> util = new ExcelUtil<UmContentFocus>(UmContentFocus.class);
        util.exportExcel(response, list, "用户文章点赞数据");
    }

    @Operation(summary = "获取用户文章点赞详细信息")
    @PreAuthorize("@ss.hasPermi('um:umContentFocus:query')")
    @GetMapping(value = "/{userId}")
    public R<UmContentFocus> getInfo(@PathVariable("userId") String userId) {
        return R.ok(umContentFocusService.selectUmContentFocusByUserId(userId));
    }

    @Operation(summary = "新增用户文章点赞")
    @PreAuthorize("@ss.hasPermi('um:umContentFocus:add')")
    @Log(title = "用户文章点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody UmContentFocus umContentFocus) {
        return toAjax(umContentFocusService.insertUmContentFocus(umContentFocus));
    }

    @Operation(summary = "修改用户文章点赞")
    @PreAuthorize("@ss.hasPermi('um:umContentFocus:edit')")
    @Log(title = "用户文章点赞", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody UmContentFocus umContentFocus) {
        return toAjax(umContentFocusService.updateUmContentFocus(umContentFocus));
    }

    @Operation(summary = "删除用户文章点赞")
    @PreAuthorize("@ss.hasPermi('um:umContentFocus:remove')")
    @Log(title = "用户文章点赞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public R remove(@PathVariable List<String> userIds) {
        return toAjax(umContentFocusService.deleteUmContentFocusByUserIds(userIds));
    }
}
